<template>
  <view>
    <view v-if="authriotyFlag" class="content">
      <uni-section type="line">
        <view class="example-body">
          <view v-for="item in titleLists" @click="clickItem(item.id)" :class="{active: item.id===checkItemId }"
            class="tag-view">
            {{ item.text }}
            <view class="line"></view>
          </view>
        </view>
      </uni-section>

      <view v-if="checkItemId == 1">
        <!-- 头部搜索-->
        <top-search ref="topSearch1Ref" :showCustomer="false" :showMore="false" :custList="custList" :rangeKey="rowKey"
          :stateList="lineupStatusList" @bindChange="bindChange" @bind1Change="bindPicker1Change"
          @bind2Change="bindPicker2Change" @bind3Change="bindPicker3Change" @confirmChange="confirmChange"
          @resetChange="resetChange"></top-search>
        <!-- 在途排号信息列表 -->
        <view class="phxx-list">
          <view class="item" v-for="(item, index) in rowNumberData">
            <row-number :itemList="item" :hasPermissionNullifyZT="hasPermissionNullifyZT"
              :hasPermissionCallZT="hasPermissionCallZT" :types="1" :authriotyFlagVoilation="authriotyFlagVoilation"
              :authriotyFlagBlck="authriotyFlagBlck" :authriotyFlagupd="authriotyFlagupd"
              @manualCalling="handleManualCalling"></row-number>
          </view>

          <uni-load-more :status="pageParams.isMore" />
        </view>
        <view class="btn">
          <button class="new" v-if="hasPermissionOnTheWay" type="primary" @click.stop="callUp1()">
            批量叫号
          </button>
        </view>
      </view>
      <view v-else>
        <!-- 头部搜索-->
        <top-search ref="topSearch2Ref" :showCustomer="false" :custList="custList" :rangeKey="rowKey" :showMore="false"
          :stateList="lineupStatusList" @bindChange="bindChange" @bind1Change="bindPicker1Change"
          @bind2Change="bindPicker2Change" @bind3Change="bindPicker3Change" @confirmChange="confirmChange"
          @resetChange="resetChange"></top-search>
        <!-- 停车场排号信息列表 -->
        <view class="phxx-list">
          <view class="item" v-for="(item, index) in parkigDatas">
            <row-number :itemList="item" :hasPermissionNullifyTCC="hasPermissionNullifyTCC"
              :hasPermissionSuspendTCC="hasPermissionSuspendTCC" :hasPermissionCallTCC="hasPermissionCallTCC" :types="2"
              :authriotyFlagVoilation="authriotyFlagVoilation" :authriotyFlagBlck="authriotyFlagBlck"
              :authriotyFlagupd="authriotyFlagupd" @manualCalling="handleManualCalling"></row-number>
          </view>
          <uni-load-more :status="pageParams.isMore" />
        </view>
        <view class="btn">
          <button class="new" v-if="hasPermissionParkingLot" type="primary" @click.stop="callUp2()">
            批量叫号
          </button>
        </view>
      </view>

      <!-- 批量叫号弹窗 -->
      <uni-popup ref="jhPopup">
        <view class="pop violation-pop">
          <view class="phxx-itemss">
            <view class="header">
              <view class="title">批量叫号</view>
            </view>
            <view class="top calling">
              <view class="infor-box">
                <uni-forms-item class="label" label="队列" required name="violationType">
                  <uni-data-select class="net-selct-box" :localdata="lineupCapacityDatas" @change="selectFun"
                    placeholder="请选择队列" label="text"></uni-data-select>
                </uni-forms-item>
                <uni-forms-item class="label" label="叫号车数" required name="violationType">
                  <uni-easyinput type="number" v-model="callLineupData.calledVehicles" placeholder="请输入叫号车数" />
                </uni-forms-item>
              </view>
            </view>
            <view class="btn">
              <button class="mini-btn" @click="close('jhPopup')" type="primary" plain="true" size="mini">
                取消
              </button>
              <button class="mini-btn" @click="confirmJiao()" type="primary" plain="true" size="mini">
                批量叫号
              </button>
            </view>
          </view>
        </view>
      </uni-popup>
      <!-- 作废 -->
      <uni-popup ref="zuofeiDialog" type="dialog">
        <uni-popup-dialog type="warn" cancelText="否" confirmText="是" :title="titleName" content="您确认要作废该排号信息吗？"
          @confirm="dialogConfirm"></uni-popup-dialog>
      </uni-popup>
      <!-- 挂起-->
      <uni-popup ref="handupDialog" type="dialog">
        <uni-popup-dialog type="warn" cancelText="否" confirmText="是" :title="titleName" content="您确认挂起该车辆的排号信息吗？"
          @confirm="dialogConfirmHandleup"></uni-popup-dialog>
      </uni-popup>
    </view>
    <view v-else class="noauth-box">
      {{ messAuth }}
    </view>
    <!-- <custom-tabbar class="tabbar-box" :list="tabbarLists"></custom-tabbar> -->
    <view class="tabbar-box">
      <view v-for="(item,index) in tabbarLists" :key="index" class="my-tabbar"
        v-if="item.pagePath == '/pages/plans/index' ? (hasMenuPer && showPlanMenu) : !item.hidden">
        <view hover-class="none" class="weui-flex__item menu-item" @click="goToTab(item.pagePath)"
          :style="item.active? 'color: '+(item.selectedColor? item.selectedColor : selectedColor) : ''">
          <image :src="item.selectedIconPath" v-if="item.active" class="img"></image>
          <image :src="item.iconPath" v-if="!item.active" class="img"></image>
          <text class='tabbar_text'>{{item.text}}</text>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
  import {
    getRowList,
    getBlackInFor,
    addBlackList,
    lineupCall,
    addViolationList,
    getParkingList,
    parkingCallNumber,
    parkingSuspend,
    lineupInvalid,
    parkingInvalid,
    lineupCalled,
    callupLineup,
    callupParking,
    getLoadsListsPage,
    getCornameListsPage,
    getCustListsPage,
    getLineupCapacityData,
    getParkingCapacityData
  } from '@/api/paihao';
  import { getCustList, getLineupStatus, getTenantConfig } from '@/api/me.js';
  import { getDictByString } from '@/utils/common';
  import { getAccessToken, getTenantId, getDriverId, getPurchaseModel, getAccountIdentity } from '@/utils/auth';
  import { getInfo } from '@/api/login';
  import { getBasisDeploy, getPurModel } from "@/api/system/user.js"
  import constant from '@/utils/constant';
  import storage from '@/utils/storage';
  import { toast, getButtonShow } from '@/utils/common.js';
  import config from '@/config';
  export default {
    data() {
      let validType = (rule, value, callback) => {
        console.log(rule, value, '请选择违规类型');
        if (!value) {
          callback(new Error('请选择违规类型'));
        } else {
          callback();
        }
      };
      return {
        hasMenuPer: true,
        showPlanMenu: getPurchaseModel() == 1 ? true : false,
        tabbarLists: [
          {
            "pagePath": "/pages/index",
            "hidden": false,
            "active": false,
            "selectedColor": '#409EFE',
            "iconPath": require("static/images/tabbar/index.png"),
            "selectedIconPath": require("static/images/tabbar/index_.png"),
            "text": "首页"
          },
          {
            "pagePath": "/pages/indexs",
            "hidden": false,
            "active": true,
            "selectedColor": '#409EFE',
            "iconPath": require("static/images/tabbar/home.png"),
            "selectedIconPath": require("static/images/tabbar/home_.png"),
            "text": "排号"
          },
          {
            "pagePath": "/pages/plans/index",
            "hidden": false,
            "active": false,
            "selectedColor": '#409EFE',
            "iconPath": require("static/images/tabbar/plan.png"),
            "selectedIconPath": require("static/images/tabbar/plan_.png"),
            "text": "计划"
          },
          {
            "pagePath": "/pages/waybill/index",
            "hidden": false,
            "active": false,
            "selectedColor": '#409EFE',
            "iconPath": require("static/images/tabbar/work.png"),
            "selectedIconPath": require("static/images/tabbar/work_.png"),
            "text": "运单"
          },
          {
            "pagePath": "/pages/mine/index",
            "hidden": false,
            "active": false,
            "selectedColor": '#409EFE',
            "iconPath": require("static/images/tabbar/mine.png"),
            "selectedIconPath": require("static/images/tabbar/mine_.png"),
            "text": "我的"
          }
        ],
        hasPermissionOnTheWay: false,
        hasPermissionParkingLot: false,
        hasPermissionNullifyZT: false,
        hasPermissionNullifyTCC: false,
        hasPermissionCallZT: false,
        hasPermissionSuspendTCC: false,
        hasPermissionCallTCC: false,
        messAuth: '',
        showPop: false,
        operateId: undefined,
        titleName: '',
        inputValue: '',
        lineupCapacityData: [],
        lineupCapacityVal: 0,
        lineupCapacityDatas: [],
        lineupCapacityName: '',
        callLineupData: {
          capacityConfigId: undefined,
          calledVehicles: undefined
        },
        checkItemId: 1,
        titleLists: [
          {
            id: 1,
            text: '在途排队'
          },
          {
            id: 2,
            text: '停车场排队'
          }
        ],
        authriotyFlag: false,
        authriotyFlagVoilation: false,
        authriotyFlagBlck: false,
        authriotyFlagupd: false,
        menus: this.$store.state.menus,
        imagesDefaultPath: config.baseUrl + 'img.png',
        fileLists: [],
        imagesPath: [],
        hasLoadPage: false,
        imagesLists: [],
        imageStyles: {
          width: 180,
          height: 110
        },
        rowKey: ['shortName', 'waybillStatusName'],
        rowNumberData: [],
        index: 0,
        itemList: {},
        // 校验规则
        blackrules: {
          blacklistReason: {
            rules: [
              {
                required: true,
                errorMessage: '黑名单原因不能为空'
              }
            ]
          },
          startTime: {
            rules: [
              {
                required: true,
                errorMessage: '开始时间不能为空'
              }
            ]
          },
          endTime: {
            rules: [
              {
                required: true,
                errorMessage: '结束时间不能为空'
              }
            ]
          },
          enableStatus: {
            rules: [
              {
                required: true,
                errorMessage: '状态不能为空'
              }
            ]
          },
          vehicleNo: {
            rules: [
              {
                required: true,
                errorMessage: '车牌号不能为空'
              }
            ]
          }
        },
        vialationrules: {
          violationType: {
            rules: [
              {
                required: true,
                errorMessage: '违规类型不能为空'
              }
            ]
          },
          violationLocation: {
            rules: [
              {
                required: true,
                errorMessage: '违规地点不能为空'
              }
            ]
          },
          violationTime: {
            rules: [
              {
                required: true,
                errorMessage: '违规时间不能为空'
              }
            ]
          },
          violationDescription: {
            rules: [
              {
                required: false,
                errorMessage: '违规描述不能为空'
              }
            ]
          }
        },
        //违规信息表单
        vialationFormData: {
          vehicleNo: undefined,
          driverName: undefined,
          driverMobile: undefined,
          waybillNo: undefined,
          violationType: undefined,
          violationTime: undefined,
          violationLocation: undefined,
          violationDescription: undefined,
          handleStatus: 1,
          handleResult: '0',
          evidencePhoto: []
        },
        //拉黑表单数据
        blackFormData: {
          blacklistReason: '',
          startTime: '',
          endTime: '',
          enableStatus: 0,
          remarks: '',
          vehicleNo: ''
        },

        //开关
        switchListText: [
          {
            title: '开',
            value: 0
          },
          {
            title: '关',
            value: 1
          }
        ],
        queryParam: {
          pageNo: 1,
          pageSize: 3,
          vehicleNo: undefined
        },
        custLists: [],
        loadLists: [],
        cornameLists: [],
        pageParams: {
          isMore: 'more'
        },
        custList: [],
        lineupStatusList: [],
        violationTypeList: [],
        parkigDatas: []
      };
    },
    onLoad() {
      console.log('页面初始化========================================');
    },
    onPullDownRefresh() {
      if (!this.authriotyFlag) return;
      this.queryParam.pageNo = 1;
      this.pageParams.isMore = 'more';
      this.rowNumberData = [];
      if (this.checkItemId == 1) {
        this.getRowList();
      } else {
        this.getParkingList();
      }
    },
    onReachBottom() {
      if (this.pageParams.isMore == 'more') {
        this.queryParam.pageNo++;
        if (this.checkItemId == 1) {
          this.getRowList();
        } else {
          this.getParkingList();
        }
      }
      console.log('onReachBottom');
    },
    methods: {
      goToTab(url) {
        wx.switchTab({
          url: url  // 需要跳转的 tab 页路径
        })
      },
      async getbuttonAuth() {
        //调用公共方法
        let per = 'onTheWayApp:batchCall';
        let per1 = 'parkingLotApp:batchCall';
        this.hasPermissionOnTheWay = await getButtonShow(per);
        this.hasPermissionParkingLot = await getButtonShow(per1);
        let onTheWayApp = 'onTheWayApp:nullify';
        let parkingLotApp = 'parkingLotApp:nullify';
        this.hasPermissionNullifyZT = await getButtonShow(onTheWayApp);
        this.hasPermissionNullifyTCC = await getButtonShow(parkingLotApp);
        let onTheWayAppCall = 'onTheWayApp:Call';
        let parkingLotAppCall = 'parkingLotApp:Call';
        this.hasPermissionCallZT = await getButtonShow(onTheWayAppCall);
        this.hasPermissionCallTCC = await getButtonShow(parkingLotAppCall);
        let parkingLotAppSuspend = 'parkingLotApp:Suspend';
        this.hasPermissionSuspendTCC = await getButtonShow(parkingLotAppSuspend);
      },

      bindPicker1Change() { },
      selectFun(e) {
        let _ = this;
        _.callLineupData.capacityConfigId = e;
      },
      async getLoadList() {
        //1.
        let data = await getLoadsListsPage({
          pageNo: 1,
          pageSize: 1000
        });
        if (!!data) this.loadLists = data.data || [];
        else this.loadLists = [];
      },
      async getCornameLists() {
        //2.
        let data = await getCornameListsPage({
          pageNo: 1,
          pageSize: 1000
        });
        if (!!data) this.cornameLists = data.data || [];
        else this.cornameLists = [];
      },
      async getCustList() {
        //3.
        let data = await getCustListsPage({
          pageNo: 1,
          pageSize: 1000
        });
        if (!!data) this.custLists = data.data || [];
        else this.custLists = [];
      },
      async callUp1() {
        let _ = this;
        _.resetForm();
        _.lineupCapacityData = [];
        _.lineupCapacityDatas = [];
        let data = await getLineupCapacityData({ queueType: 1 });
        let curname = '',
          curname1 = '';
        let curnameLists = [];
        let curIdsLists = [];
        let isComp = false;
        let curIdsLists1 = [];
        let curnameLists1 = [];
        !!data &&
          data.data.length > 0 &&
          data.data.forEach((ele) => {
            curname = '';
            curname1 = '';
            isComp = false;
            curnameLists = [];
            curIdsLists = [];
            curIdsLists1 = [];
            curnameLists1 = [];
            if (ele.supplierIds != null && ele.supplierIds.length > 0) {
              if (ele.coalIds != null && ele.coalIds.length > 0) {
                //供应商+煤种
                isComp = true;
                curIdsLists = ele.supplierIds;
                curnameLists = _.custLists;

                curIdsLists1 = ele.coalIds;
                curnameLists1 = _.cornameLists;
              } else if (ele.loadSiteIds != null && ele.loadSiteIds.length > 0) {
                //供应商+装货地
                isComp = true;
                curIdsLists = ele.supplierIds;
                curnameLists = _.custLists;

                curIdsLists1 = ele.loadSiteIds;
                curnameLists1 = _.loadLists;
              } else {
                //供应商
                curIdsLists = ele.supplierIds;
                curnameLists = _.custLists;
              }
            } else {
              if (ele.coalIds != null && ele.coalIds.length > 0) {
                //煤种
                curIdsLists = ele.coalIds;
                curnameLists = _.cornameLists;
                if (ele.customerIds != null && ele.customerIds.length > 0) {
                  //客户+煤种
                  curIdsLists = ele.customerIds;
                  curnameLists = _.custLists;
                }
              } else if (ele.customerIds != null && ele.customerIds.length > 0) {
                //客户
                curIdsLists = ele.customerIds;
                curnameLists = _.custLists;
              } else if (ele.loadSiteIds != null && ele.loadSiteIds.length > 0) {
                //装货地
                curIdsLists = ele.loadSiteIds;
                curnameLists = _.loadLists;
              }
            }
            let k = {},
              k1 = {};
            curIdsLists.forEach((id) => {
              k = curnameLists.find((el) => {
                return el.id == id;
              });
              curname +=
                (!!k && (k.coalName || k.shortName || k.siteName) + ',') || '';
            });
            if (isComp) {
              curIdsLists1.forEach((id) => {
                k1 = curnameLists1.find((el) => el.id == id);
                curname1 +=
                  (!!k1 && (k1.coalName || k1.shortName || k1.siteName) + ',') ||
                  '';
              });
              ele['coalName'] =
                curname.replace(/\,$/, '') + '+' + curname1.replace(/\,$/, '');
            } else ele['coalName'] = curname.replace(/\,$/, '');
            _.lineupCapacityData.push(ele['coalName']);
            if (ele.queueSetupType === 8) {
              _.lineupCapacityDatas.push({
                value: ele.id,
                text: ele.purchaserName
              });
            } else if (ele.queueSetupType === 9) {
              const loadSiteName = curnameLists.find(
                (e) => e.id.toString() === ele.loadSiteIds[0]
              )?.siteName;
              _.lineupCapacityDatas.push({
                value: ele.id,
                text: `${ele.purchaserName},${loadSiteName}`
              });
            } else {
              _.lineupCapacityDatas.push({
                value: ele['id'],
                text: ele['coalName']
              });
            }
          });
        _.showPop = true;
        _.$refs['jhPopup'].open();
      },
      async callUp2() {
        let _ = this;
        _.resetForm();
        _.lineupCapacityData = [];
        _.lineupCapacityDatas = [];
        let data = await getParkingCapacityData({ status: 0 });
        let curname = '',
          curname1 = '';
        let curnameLists = [];
        let curIdsLists = [];
        let isComp = false;
        let curIdsLists1 = [];
        let curnameLists1 = [];

        !!data &&
          data.data.length > 0 &&
          data.data.forEach((ele) => {
            curname = '';
            curname1 = '';
            isComp = false;
            curnameLists = [];
            curIdsLists = [];

            curIdsLists1 = [];
            curnameLists1 = [];
            if (!!ele.supplierName) {
              if (!!ele.purchaseCoalName) {
                //供应商+煤种
                ele['coalName'] = ele.supplierName + '+' + ele.purchaseCoalName;
              } else if (!!ele.loadSiteName) {
                //供应商+装货地
                ele['coalName'] = ele.supplierName + '+' + ele.loadSiteName;
              } else {
                //供应商
                ele['coalName'] = ele.supplierName;
              }
            } else {
              if (!!ele.purchaseCoalName) {
                //煤种
                ele['coalName'] = ele.purchaseCoalName;
              } else if (!!ele.customerName) {
                //客户
                ele['coalName'] = ele.customerName;
              } else if (!!ele.loadSiteName) {
                //装货地
                ele['coalName'] = ele.loadSiteName;
              }
            }
            _.lineupCapacityData.push(ele['coalName']);
            if (ele.queueSetupType === 7) {
              _.lineupCapacityDatas.push({
                value: ele.id,
                text: ele.purchaserName
              });
            } else if (ele.queueSetupType === 8) {
              _.lineupCapacityDatas.push({
                value: ele.id,
                text: `${ele.purchaserName},${ele.loadSiteName}`
              });
            } else {
              _.lineupCapacityDatas.push({
                value: ele['id'],
                text: ele['coalName']
              });
            }
          });
        this.showPop = true;
        this.$refs['jhPopup'].open();
      },
      clickItem(id) {
        this.checkItemId = id;
        this.queryParam = {
          pageNo: 1,
          pageSize: 3,
          vehicleNo: undefined
        };
        if (id == 1) {
          this.getRowList();
        } else {
          this.getParkingList();
        }
      },
      async getTenantConfig() {
        let res = await getTenantConfig();
        if (res.code === 0) {
          return res.data.parkingEnableStatus === 0;
        } else {
          return false;
        }
      },
      async getParkingList() {
        let flag = await this.getTenantConfig();
        console.log('flag---是否开启停车场排队----->', flag);
        if (!flag) {
          wx.stopPullDownRefresh();
          return;
        }
        try {
          //遍历对象过滤空值
          let data = {};
          Object.keys(this.queryParam).forEach((item) => {
            if (this.queryParam[item]) {
              data[item] = this.queryParam[item];
            }
          });
          this.pageParams.isMore = 'loading';
          let res = await getParkingList(data);
          if (res.code == 0) {
            if (this.queryParam.pageNo == 1) {
              this.parkigDatas = res.data.list;
            } else {
              this.parkigDatas = [...this.parkigDatas, ...res.data.list];
            }
            if (res.data.total == this.parkigDatas.length) {
              this.pageParams.isMore = 'noMore';
            } else {
              this.pageParams.isMore = 'more';
            }
          } else {
            this.parkigDatas = [];
            this.pageParams.isMore = 'noMore';
          }

          wx.stopPullDownRefresh();
        } catch (e) {
          return false;
        }
      },
      getMenuAuth() {
        this.authriotyFlagVoilation = false;
        this.authriotyFlagBlck = false;
        this.authriotyFlagupd = false;

        let menusLists = [];
        this.$store.dispatch('GetUserAuthority').then(async (res) => {
          if (res.code == '200') {
            menusLists = res.data || [];
            console.log(menusLists, '这是排号信息的menu=======');
            let menuItem = [];
            if (menusLists.length > 0) {
              //有菜单再去判断按钮
              let permissionsLists = [];
              let plists = await getInfo({
                enterId: getTenantId(),
                userId: getDriverId()
              });
              permissionsLists = plists?.data?.permissions || [];

              menuItem = menusLists.find((item) => item.id == 411); //'在途排队'
              let menuItemCur = [];
              if (!!menuItem) {
                if (!!menuItem.children)
                  menuItemCur = menuItem.children.find((item) => item.id == 421); //"在途排号"
              }
              if (!!menuItemCur) {
                this.authriotyFlag = true;
                this.getLoadList();
                this.getCornameLists();
                this.getRowList();
                this.getCustList();
                this.getLineupState();


                console.log(permissionsLists, '这是排号信息的permissions=======');
                let menuItem1 = [],
                  menuItem2 = [],
                  menuItem3 = [];
                if (permissionsLists.length > 1) {
                  menuItem1 = permissionsLists.find(
                    (item) => item == 'queue:violation-info-mgr:create'
                  );
                  menuItem2 = permissionsLists.find(
                    (item) => item == 'queue:blacklist-config:create'
                  );
                  menuItem3 = permissionsLists.find(
                    (item) => item == 'queue:lineup-info-mgr:call'
                  );

                  if (!!menuItem1) this.authriotyFlagVoilation = true;
                  if (!!menuItem2) this.authriotyFlagBlck = true;
                  if (!!menuItem3) this.authriotyFlagupd = true;
                }
              } else {
                this.messAuth = '您无权查看此页面！请联系管理员';
                this.authriotyFlag = false;
              }
            } else {
              this.messAuth = '您无权查看此页面！请联系管理员';
              this.authriotyFlag = false;
            }
          } else {
            console.log('访问菜单权限出错...');
          }
        });
      },
      resetForm(res) {
        this.callLineupData = {
          capacityConfigId: undefined,
          calledVehicles: undefined
        };
      },
      goToDetail(item) {
        wx.navigateTo({ url: '/pages/lineup/index?id=' + item.id });
      },
      confirmChange(data) {
        this.rowNumberData = [];
        this.parkigDatas = [];
        this.queryParam.vehicleNo = data.vehicleNo;
        this.queryParam.queueStatus = data.waybillStatus;
        this.queryParam.startTime = data.startTime;
        this.queryParam.endTime = data.endTime;
        if (this.checkItemId == 1) {
          this.getRowList();
        } else {
          this.getParkingList();
        }
      },
      photoSuccess(e) {
        console.log('触发了上传select123', e);
      },
      progress(e) {
        console.log('上传进度：', e);
      },
      // 上传成功
      success(e) {
        console.log('上传成功', e);
      },
      // 上传失败
      fail(e) {
        console.log('上传失败：', e);
      },
      deleteF(e) {
        this.fileLists.splice(this.fileLists.indexOf(e.tempFile.url), 1);
        this.vialationFormData.evidencePhoto.splice(
          this.fileLists.indexOf(e.tempFile.url),
          1
        );
      },
      select(e) {
        let that = this;
        let imgLists = e.tempFilePaths;
        imgLists.forEach((item) => {
          that.uploadFiles(item);
          that.fileLists.push({
            url: item,
            extname: item.split('/')[item.split('/').length - 1].split('.')[1],
            name: item.split('/')[item.split('/').length - 1]
          });
        });
      },
      // 上传函数
      async uploadFiles(tempFilePaths) {
        console.log('···uploadFiles', tempFilePaths);
        let that = this;
        return new Promise(async (resolve, reject) => {
          await uni.uploadFile({
            // url: 'https://test.8ykj.cn/api/app-api/infra/file/upload', //后端用于处理图片并返回图片地址的接口
            // url: 'https://api.8ykj.cn/app-api/infra/file/upload',
            url: config.baseUrl + config.baseApi + '/infra/file/upload',
            filePath: tempFilePaths,
            name: 'file',
            header: {
              Authorization: 'Bearer ' + getAccessToken(),
              'Content-Type': 'multipart/form-data'
            },
            success: (res) => {
              console.log(res, '···uploadFile222');
              let data = JSON.parse(res.data); //返回的是字符串，需要转成对象格式
              if (data.code == 0) {
                console.log(data.data, '');
                that.vialationFormData.evidencePhoto =
                  that.vialationFormData.evidencePhoto.concat(data.data);
                resolve(data.data);
              }
            },
            fail: (err) => {
              console.log('err', err);
            }
          });
        });
      },
      // 移出图片函数
      async deletephoto() {
        console.log('shanchu');
      },

      //客户选择处理
      bindPicker1Change(item) {
        console.log(item, '选择客户');
        this.queryParam.pageNo = 1;
        this.queryParam.customerId = item.id;
        this.rowNumberData = [];
        this.getRowList();
      },
      bindPicker2Change(item) {
        console.log(item, '选择状态');
        this.queryParam.pageNo = 1;
        this.queryParam.queueStatus = item.waybillStatus;
        this.rowNumberData = [];
        this.getRowList();
      },
      bindPicker3Change(item) {
        console.log(item, '选择时间');
        this.queryParam.pageNo = 1;
        this.queryParam.startTime = item[0];
        this.queryParam.endTime = item[1];
        this.rowNumberData = [];
        this.getRowList();
      },
      bindChange(item) {
        console.log(item, '选择时间');
        this.queryParam.pageNo = 1;
        this.queryParam.vehicleNo = item.vehicleNo;
        if (this.checkItemId == 1) {
          this.rowNumberData = [];
          this.getRowList();
        } else {
          this.parkigDatas = [];
          this.getParkingList();
        }
      },
      resetChange() {
        this.queryParam = {
          pageNo: 1,
          pageSize: 3,
          vehicleNo: '',
          customerId: '',
          queueStatus: ''
        };
        this.rowNumberData = [];
        this.getRowList();
      },

      //获取排号状态
      async getLineupState() {
        try {
          let res = await getLineupStatus({ businessType: 1 });
          if (res.code == 0) {
            this.lineupStatusList = res.data;
          }
        } catch (e) {
          return false;
        }
      },

      //获取排号信息列表
      async getRowList() {
        try {
          //遍历对象过滤空值
          let data = {};
          Object.keys(this.queryParam).forEach((item) => {
            if (this.queryParam[item]) {
              data[item] = this.queryParam[item];
            }
          });
          this.pageParams.isMore = 'loading';
          let res = await getRowList(data);
          if (res.code == 0) {
            if (this.queryParam.pageNo == 1) {
              this.rowNumberData = res.data.list;
            } else {
              this.rowNumberData = [...this.rowNumberData, ...res.data.list];
            }
            if (res.data.total == this.rowNumberData.length) {
              this.pageParams.isMore = 'noMore';
            } else {
              this.pageParams.isMore = 'more';
            }
          }

          wx.stopPullDownRefresh();
        } catch (e) {
          return false;
        }
      },

      //作废弹窗
      async dialogConfirm() {
        let res = {};
        if (this.checkItemId == 1) {
          res = await lineupInvalid(this.operateId);
        } else {
          res = await parkingInvalid(this.operateId);
        }
        if (res.code == 0) {
          // 叫号成功
          uni.showToast({
            title: `作废成功`
          });
        } else {
          // 叫号失败
          toast(res.msg);
        }
        this.queryParam.pageNo = 1;
        this.close('zuofeiDialog');
        if (this.checkItemId == 1) {
          this.getRowList();
        } else {
          this.getParkingList();
        }
      },
      //挂起弹窗
      async dialogConfirmHandleup() {
        let res = await parkingSuspend(this.operateId);
        if (res.code == 0) {
          // 叫号成功
          uni.showToast({
            title: `挂起成功`
          });
        } else {
          // 叫号失败
          toast(res.msg);
        }
        this.close('handupDialog');
        this.queryParam.pageNo = 1;
        if (this.checkItemId == 1) {
          this.getRowList();
        } else {
          this.getParkingList();
        }
      },
      switchChangeFun(e) {
        console.log('触发 switchChangeFun', e.swithcSelectItem.value);
        //重新赋值，改变该值用于设置switch默认值
        this.blackFormData.enableStatus = e.swithcSelectItem.value;
      },
      // 弹框逻辑
      async handleManualCalling(item, type) {
        let _ = this;
        _.operateId = item.id;
        switch (type) {
          case 1:
            //排队 作废
            _.titleName = '提示';
            _.$refs['zuofeiDialog'].open();
            break;
          case 2:
            //排队 手动叫号
            let res = await lineupCalled(item.id);
            if (res.code == 0) {
              // 叫号成功
              uni.showToast({
                title: `叫号成功`
              });
            } else {
              // 叫号失败
              toast(res.msg);
            }
            this.queryParam.pageNo = 1;
            if (this.checkItemId == 1) {
              this.getRowList();
            } else {
              this.getParkingList();
            }
            break;
          case 3:
            //停车场 作废
            _.titleName = '提示';
            _.$refs['zuofeiDialog'].open();
            break;
          case 4:
            //停车场 挂起
            _.$refs['handupDialog'].open();
            break;
          case 5:
            //停车场 手动叫号
            let resp = await parkingCallNumber(item.id);
            if (resp.code == 0) {
              // 叫号成功
              uni.showToast({
                title: `叫号成功`
              });
            } else {
              // 叫号失败
              toast(resp.msg);
            }
            this.queryParam.pageNo = 1;
            if (this.checkItemId == 1) {
              this.getRowList();
            } else {
              this.getParkingList();
            }
            break;
          default:
            break;
        }
      },
      close(ref) {
        this.$refs[ref].close();
      },

      async confirmJiao() {
        if (!this.callLineupData.capacityConfigId) {
          toast(`请选择队列`);
          return;
        }
        if (!this.callLineupData.calledVehicles) {
          toast(`请输入叫号车数`);
          return;
        }
        uni.showModal({
          title: '叫号确认框',
          content: '您确认批量叫号车辆的排号信息吗？',
          success: async (res) => {
            if (res.confirm) {
              if (this.checkItemId == 1) {
                try {
                  let res = await callupLineup(this.callLineupData);
                  console.log('lineupCall: ', res);
                  if (res.code == 0) {
                    // 叫号成功
                    uni.showToast({
                      title: `叫号成功`
                    });
                    // 刷新页面
                    this.queryParam.pageNo = 1;
                    this.pageParams.isMore = 'more';
                    this.rowNumberData = [];
                    this.showPop = false;
                    this.$refs['jhPopup'].close();
                    this.getRowList();
                  } else {
                    toast(res.msg);
                  }
                } catch (e) {
                  this.showPop = false;
                  this.close('jhPopup');
                }
              } else {
                try {
                  let res = await callupParking(this.callLineupData);
                  console.log('lineupCall: ', res);
                  if (res.code == 0) {
                    // 叫号成功
                    uni.showToast({
                      title: `叫号成功`
                    });
                    // 刷新页面
                    this.queryParam.pageNo = 1;
                    this.pageParams.isMore = 'more';
                    this.rowNumberData = [];
                    this.showPop = false;
                    this.$refs['jhPopup'].close();
                    this.getRowList();
                  } else {
                    toast(res.msg);
                  }
                } catch (e) {
                  this.showPop = false;
                  this.close('jhPopup');
                }
              }
            } else if (res.cancel) {
            }
          }
        });
      }
    },
    async onShow() {
      let purmodel = await getPurModel()
      if (purmodel.code == 0) {
        this.showPlanMenu = purmodel.data.purchaseBizMode == 1 ? true : false
      }
      let permissionsLists = [];
      let plists = await getInfo({
        enterId: getTenantId(),
        userId: getDriverId()
      });
      permissionsLists = plists?.data?.permissions || [];
      this.hasMenuPer = permissionsLists.some(
        (item) => item == 'plan:view'
      );
      console.log(getAccountIdentity())
      this.queryParam.pageNo = 1;
      this.queryParam.vehicleNo = undefined;
      this.rowNumberData = [];
      this.checkItemId = 1
      this.$refs.topSearch1Ref?.resetForm()
      this.$refs.topSearch2Ref?.resetForm()
      this.getMenuAuth();
      this.getbuttonAuth();
    }
  };
</script>

<style lang="scss" scoped></style>